/* eslint-disable no-extend-native, func-names, prefer-arrow-callback, prefer-template */

String.prototype.splice = function splice(start, delCount, newSubStr) {
  return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
};

Promise.delay = function (ms) {
  return new Promise(function (resolve) {
    setTimeout(resolve, ms);
  });
};

Promise.prototype.timeout = function (time, message) {
  const timeout = Promise.delay(time).then(function () {
    throw new Error(message || 'Operation timed out after ' + time + ' ms');
  });

  return Promise.race([this, timeout]);
};
